package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.JdbcTemplate.WXJdbc;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import com.wuseguang.springcloud.util.WeChat.WXUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 检测
 */
@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private WXJdbc wXJdbc;

    @PostMapping("/checkContentAndPic")
    public Result checkContentAndPic(@RequestParam(value = "content", defaultValue = "") String content,
                                     @RequestPart(value = "file",required = false) MultipartFile file,
                                    @RequestParam(value = "type", required = false) Integer type ) {
        Boolean flag = true;

        if(flag && !StringUtils.isEmpty(content)) {
            flag = WXUtil.checkContent(wXJdbc.getAccessToken(type), content);
        }
        if(flag && !StringUtils.isEmpty(file)) {
            flag = WXUtil.checkPic(wXJdbc.getAccessToken(type), file);
        }

        return flag ? new Result<>() : new Result(CodeUtil.SENSITIVE_INFORMATION_DETECTED);
    }
}
